#include "StdAfx.h"
#include "UCListHeader.h"


CUCListHeader::CUCListHeader(void)
{
}

CUCListHeader::~CUCListHeader(void)
{
}

void CUCListHeader::SetLeftImage(LPCTSTR lpszImage)
{
	m_sLeftImage = lpszImage;
}

void CUCListHeader::SetRightImage(LPCTSTR lpszImage)
{
	m_sRightImage = lpszImage;
}

void CUCListHeader::SetAttribute(LPCTSTR pstrName, LPCTSTR pstrValue)
 {
	 if( _tcsicmp(pstrName, _T("LeftImage")) == 0 )
	 {
		 SetLeftImage(pstrValue);
		 return;
	 }
	 else if( _tcsicmp(pstrName, _T("RightImage")) == 0 )
	 {
		 SetRightImage(pstrValue);
		 return;
	 }

	 __super::SetAttribute(pstrName,pstrValue);
 }


void CUCListHeader::PaintBkImage(HDC hDC)
{
	if( m_sBkImage.IsEmpty() ) return;

	RECT rc = m_rcItem;
	if (m_pManager)
	{
		TImageInfo *pImageInfo = NULL;
		if (!m_sLeftImage.IsEmpty())
		{
			TImageInfo *pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sLeftImage.GetData());
			if (!pImageInfo)
			{
				m_pManager->AddImage(m_sLeftImage.GetData());
				pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sLeftImage.GetData());
			}

			if (pImageInfo)
			{
				rc.left += pImageInfo->nX;
			}
		}

		if (!m_sRightImage.IsEmpty())
		{
			pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sRightImage.GetData());
			if (!pImageInfo)
			{
				m_pManager->AddImage(m_sRightImage.GetData());
				pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sRightImage.GetData());
			}

			if (pImageInfo)
			{
				rc.right -= pImageInfo->nX;
			}
		}
	}

	CRenderEngine::DrawImageString(hDC, m_pManager, rc, m_rcPaint,m_sBkImage,NULL);
}

void CUCListHeader::DoPaint(HDC hDC, const RECT& rcPaint)
{
	__super::DoPaint(hDC,rcPaint);
	if (m_pManager)
	{
		TImageInfo *pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sLeftImage);
		if (!pImageInfo)
		{
			m_pManager->AddImage(m_sLeftImage);
			pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sLeftImage);
		}

		if (pImageInfo)
		{
			RECT rc = m_rcItem;
			rc.right = rc.left + pImageInfo->nX;
			CRenderEngine::DrawImageString(hDC, m_pManager, rc, rcPaint, m_sLeftImage,NULL);
		}

		pImageInfo = NULL;

		pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sRightImage);
		if (!pImageInfo)
		{
			m_pManager->AddImage(m_sRightImage.GetData());
			pImageInfo = (TImageInfo*)m_pManager->GetImage(m_sRightImage);
		}

		if (pImageInfo)
		{
			RECT rc = m_rcItem;
			rc.left = rc.right - pImageInfo->nX;
			CRenderEngine::DrawImageString(hDC, m_pManager, rc, rcPaint, m_sRightImage,NULL);
		}
	}
	/*m_pManager->geti*/
	// return CRenderEngine::DrawImageString(hDC, m_pManager, m_rcItem, m_rcPaint, pStrImage, pStrModify);
}
